package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.db.QuestionsApi;
import com.tanhua.dubbo.api.mapper.QuestionsMapper;
import com.tanhua.model.db.Questions;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 问题持久层实现类
 */
@DubboService
public class QuestionsApiImpl implements QuestionsApi {

    @Autowired
    private QuestionsMapper questionsMapper;

    /**
     * 根据问卷Id查询对应问题列表
     */
    @Override
    public List<Questions> findQuestionsByQaId(String QaId) {
        QueryWrapper<Questions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("questionnaires_id",QaId);
        return questionsMapper.selectList(queryWrapper);
    }

    /**
     * 通过试题编号获取问卷编号
     * @param questionId
     * @return
     */
    @Override
    public String findQuestionairesId(String questionId) {
        QueryWrapper<Questions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("questions_id",questionId);
        Questions questions = questionsMapper.selectOne(queryWrapper);
        return questions.getQuestionnairesId();
    }

    /**
     * 根据题号查询维度号
     * @param questionId
     * @return
     */
    @Override
    public String findDimensions(String questionId) {
        QueryWrapper<Questions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("questions_id",questionId);
        Questions questions = questionsMapper.selectOne(queryWrapper);
        return questions.getDimensionsId();
    }


}
